/*     */ package com.infoservice.schedule.test.task;
/*     */ 
/*     */ import com.infoservice.po3.POFactory;
/*     */ import com.infoservice.po3.POFactoryBuilder;
/*     */ import com.infoservice.po3.bean.PageResult;
/*     */ import com.infoservice.po3.callbackimpl.POCallBack;
/*     */ import com.infoservice.po3.core.context.POContext;
/*     */ import com.infoservice.po3.core.exceptions.DAOException;
/*     */ import com.infoservice.schedule.po.pos.TaskPO;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Calendar;
/*     */ import java.util.Date;
/*     */ import java.util.LinkedList;
/*     */ import java.util.List;
/*     */ import java.util.TimerTask;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class GenMinTask extends TimerTask
/*     */ {
/*  39 */   private Logger log = Logger.getLogger(GenMinTask.class);
/*  40 */   private SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/*  41 */   private int planInterval = 300000;
/*  42 */   private int startTimeOut = 60000;
/*  43 */   private String startTime = "11:39";
/*  44 */   private String endTime = "12:00";
/*  45 */   private String sql = "select * from task where task_id = 10025 and plan_id = 10025 order by plan_start_time desc";
/*     */ 
/*  47 */   public Date getFirstDate() { Calendar cur = Calendar.getInstance();
/*  48 */     cur.set(14, 0);
/*  49 */     cur.set(13, 0);
/*     */     try {
/*  51 */       Calendar start = Calendar.getInstance();
/*  52 */       start.set(14, 0);
/*  53 */       start.set(13, 0);
/*  54 */       start.set(11, Integer.parseInt(this.startTime.split(":")[0]));
/*  55 */       start.set(12, Integer.parseInt(this.startTime.split(":")[1]));
/*  56 */       if (start.getTimeInMillis() >= cur.getTimeInMillis()) {
/*  57 */         localDate = new Date(start.getTimeInMillis() - 600000L);
/*     */         return localDate;
/*     */       }
/*     */ 
/*  60 */       localDate = getNextPlanTime(start.getTime(), cur.getTime());
/*     */       return localDate;
/*     */     }
/*     */     catch (Exception e) {
/*  63 */       POContext.endTxn(false);
/*  64 */       Date localDate = cur.getTime();
/*     */       return localDate;
/*     */     } finally {
/*  66 */       POContext.cleanTxn();
/*  67 */     }throw localObject; }
/*     */ 
/*     */   public Date getNextPlanTime(Date date, Date curDate) {
/*  70 */     this.log.info("curDate=======" + this.df.format(curDate));
/*  71 */     long preLong = date.getTime();
/*  72 */     long curLong = curDate.getTime();
/*  73 */     long temp = curLong - preLong;
/*  74 */     this.log.info("temp======" + temp);
/*  75 */     long times = temp / this.planInterval;
/*  76 */     this.log.info("times=======" + times);
/*  77 */     Date next = new Date(preLong + times * this.planInterval);
/*  78 */     this.log.info("nextDate=======" + this.df.format(next));
/*  79 */     return next;
/*     */   }
/*     */   public Date getEndDate() {
/*  82 */     Calendar cur = Calendar.getInstance();
/*  83 */     cur.set(14, 0);
/*  84 */     cur.set(13, 0);
/*  85 */     String[] temp = this.endTime.split(":");
/*  86 */     cur.set(11, Integer.parseInt(temp[0]));
/*  87 */     cur.set(12, Integer.parseInt(temp[1]));
/*  88 */     return cur.getTime();
/*     */   }
/*     */ 
/*     */   public void run()
/*     */   {
/*     */     try
/*     */     {
/*  99 */       Calendar cur = Calendar.getInstance();
/* 100 */       cur.set(14, 0);
/* 101 */       cur.set(13, 0);
/* 102 */       Calendar start = Calendar.getInstance();
/* 103 */       start.set(14, 0);
/* 104 */       start.set(13, 0);
/* 105 */       start.set(11, Integer.parseInt(this.startTime.split(":")[0]));
/* 106 */       start.set(12, Integer.parseInt(this.startTime.split(":")[1]));
/* 107 */       POFactory factory = POFactoryBuilder.getInstance();
/* 108 */       TaskPO task = null;
/* 109 */       List ret = new LinkedList();
/* 110 */       List list = factory.pageQuery(this.sql, null, new POCallBack(factory, TaskPO.class), 1, 1).getRecords();
/* 111 */       List lis = null;
/* 112 */       if ((list != null) && (list.size() > 0)) {
/* 113 */         for (int i = 0; i < list.size(); i++) {
/* 114 */           if (((TaskPO)list.get(i)).getPlanStartTime() != null)
/* 115 */             lis = genDate(((TaskPO)list.get(i)).getPlanStartTime(), this.planInterval, cur.getTime());
/*     */           else {
/* 117 */             lis = genDate(start.getTime(), this.planInterval, cur.getTime());
/*     */           }
/*     */         }
/*     */       }
/*     */       else {
/* 122 */         lis = genDate(start.getTime(), this.planInterval, cur.getTime());
/*     */       }
/* 124 */       if (lis.size() > 0) {
/* 125 */         for (int j = 0; j < lis.size(); j++) {
/* 126 */           if ((((Date)lis.get(j)).after(cur.getTime())) && (((Date)lis.get(j)).getTime() - cur.getTimeInMillis() <= 600000L)) {
/* 127 */             task = new TaskPO();
/* 128 */             task.setPlanId(Long.valueOf(10025L));
/* 129 */             task.setTaskId(Long.valueOf(10025L));
/* 130 */             task.setMarker(Integer.valueOf(0));
/* 131 */             task.setPlanStartTime((Date)lis.get(j));
/* 132 */             task.setIgnoreFlag(Integer.valueOf(0));
/* 133 */             task.setStartTimeout(Integer.valueOf(100000));
/* 134 */             task.setLogId(factory.getLongPK(task));
/* 135 */             ret.add(task);
/*     */           }
/* 137 */           if ((((Date)lis.get(j)).before(cur.getTime())) && (cur.getTimeInMillis() - ((Date)lis.get(j)).getTime() <= this.startTimeOut)) {
/* 138 */             task = new TaskPO();
/* 139 */             task.setPlanId(Long.valueOf(10025L));
/* 140 */             task.setTaskId(Long.valueOf(10025L));
/* 141 */             task.setMarker(Integer.valueOf(0));
/* 142 */             task.setPlanStartTime((Date)lis.get(j));
/* 143 */             task.setIgnoreFlag(Integer.valueOf(0));
/* 144 */             task.setStartTimeout(Integer.valueOf(100000));
/* 145 */             task.setLogId(factory.getLongPK(task));
/* 146 */             ret.add(task);
/*     */           }
/*     */         }
/*     */       }
/* 150 */       factory.insert(ret);
/* 151 */       POContext.endTxn(true);
/*     */     } catch (DAOException e) {
/* 153 */       POContext.endTxn(false);
/* 154 */       this.log.error(e.getMessage(), e);
/*     */     } catch (Exception e) {
/* 156 */       POContext.endTxn(false);
/* 157 */       this.log.error(e.getMessage(), e);
/*     */     } finally {
/* 159 */       POContext.cleanTxn();
/*     */     }
/*     */   }
/*     */ 
/*     */   public List<Date> genDate(Date planStartDate, long interval, Date curDate) {
/* 163 */     List list = new LinkedList();
/* 164 */     long begin = planStartDate.getTime();
/* 165 */     while (begin <= curDate.getTime() + 600000L) {
/* 166 */       list.add(new Date(begin + interval));
/* 167 */       begin += interval;
/*     */     }
/* 169 */     this.log.info("list==========" + list.toString());
/* 170 */     return list;
/*     */   }
/*     */ }

/* Location:           D:\Workspace\Work\ASMP_DE\lib\frame3\InfoSchedule_1.0.03.jar
 * Qualified Name:     com.infoservice.schedule.test.task.GenMinTask
 * JD-Core Version:    0.6.0
 */